import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Jiang Jinxi
 * Date: 2024-08-30
 * Time: 20:13
 */
public class Demo20 {
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Thread t1 = new Thread(() -> {
            synchronized(locker){
                System.out.println("t1等待前");
                try {
                    locker.wait(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1等待后");
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized(locker){
                System.out.println("t2等待前");

                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t2等待后");
            }
        });
        Thread t3 = new Thread(() -> {
            synchronized(locker){
                System.out.println("t3通知前");
                Scanner scanner = new Scanner(System.in);
                scanner.nextInt();
                locker.notifyAll();
                System.out.println("t3通知后");

            }
        });
        t1.start();
        t2.start();
        Thread.sleep(100);
        t3.start();
    }
}
